package com.qyhl.module_practice.rank.street;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeListBean;

import java.util.List;

public class PracticeStreetRankModel implements PracticeStreetRankContract.PracticeStreetRankModel {
    private PracticeStreetRankPresenter mPresenter;

    PracticeStreetRankModel(PracticeStreetRankPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String instId, String page, int type) {
        String url = "";
        switch (type) {
            case 1:
                url = PracticeUrl.GET_STREET_LIST_BY_TIME;
                break;
            case 2:
                url = PracticeUrl.GET_STREET_LIST_BY_ACT;
                break;
            case 3:
                url = PracticeUrl.GET_STREET_LIST_BY_SCORE;
                break;
        }
        EasyHttp.get(url)
                .params("instId", instId)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何实践单位！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取列表失败，请重新尝试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeListBean> practiceListBeans) {
                        if (practiceListBeans!= null && practiceListBeans.size() > 0) {
                            mPresenter.setList(practiceListBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何实践单位！", !page.equals("1"));
                        }
                    }
                });
    }
}
